package demo;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-05-25
 * Time: 19:41
 */
public class MyStack {
    private int[] elem ;
    private int useSize ;
    private static final int DEFAULT_SIZE = 10 ;
    public MyStack(){
        this.elem = new  int[DEFAULT_SIZE] ;
    }
    public void push(int data){
        if(this.useSize == this.elem.length){
           this.elem = Arrays.copyOf(this.elem,this.elem.length * 2) ;
        }
        this.elem[this.useSize++] = data ;

    }
    public boolean isFull(){
       return this.elem.length == this.useSize;
    }

    public int pop(){
        if(isEmpty()){
         new EmptyException() ;
        }
        this.useSize -- ;
        return this.elem[useSize] ;
    }
    public int peek(){
        if(isEmpty()){
            new EmptyException() ;
        }
        return this.elem[useSize-1 ] ;
    }
    public boolean isEmpty(){
        return this.useSize == 0 ;
    }


}
